﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HustQQInterface;

namespace HustQQServer.DataBase
{
    public class DataImplement:IDataInterface
    {

        public List<string> GetTeams(string myId)
        {

            return TeamDB.GetAllTeams(myId);
        }


        public bool Login(string userId, string pwd)
        {
            string pwds = UserDB.GetPassword(userId);
            if (pwds != null && pwds.CompareTo(pwd) == 0)
            {
                return true;
            }
            else
            {
                return false;
            }
            
        }



        public string Register(HustQQModel.User u)
        {
            return  UserDB.InsertUsr(u);
        }

        public HustQQModel.User GetUserInformation(string userId, bool isDetail)
        {
            HustQQModel.User u =  UserDB.GetUserInfo(userId, isDetail);
            u.friends = UserDB.GetFriends(userId);
            return u;
        }

        public bool AddFriendToUser(string myId, string friendId)
        {
            return UserDB.addAFriend(myId, friendId);
        }

        public bool AddFriendToGroup(string myId, string friendId, string groupName)
        {
            return UserDB.addAFriend(myId, friendId, groupName);
        }

        public bool DelFriendFromUser(string myId, string friendId)
        {
            UserDB.deleteAFriend(myId, friendId);
            throw new NotImplementedException();
        }

        public bool DelFriendFromGroup(string myId, string friendId, string groupName)
        {
            UserDB.deleteAFriend(myId, friendId);
            throw new NotImplementedException();
        }

        public bool SetUserInformation(HustQQModel.User u)
        {
            //??????????????????????????????
            UserDB.UpdateUsr(u);
            throw new NotImplementedException();
        }

        public string NewTeamToUser(string myId, string teamName)
        {
            return TeamDB.NewTeam(myId, teamName);
            
        }

        public HustQQModel.Team GetTeamInformation(string teamId, bool isDetail)
        {
            List<string> memberList = new List<string>();
            
            HustQQModel.Team ateam = new HustQQModel.Team();

            if (isDetail)
            {
                memberList = TeamDB.GetGroupMemberID(teamId);

                ateam.members = memberList;
            }
            
            ateam.teamID = teamId;
            ateam.teamName = TeamDB.GetGroupName(teamId);

            return ateam;
        }

        public bool SetTeamInformation(HustQQModel.Team t)
        {
            //nonononononononononono

            throw new NotImplementedException();
        }

        public bool AddFriendToTeam(string teamId, string userId)
        {
            return TeamDB.InsertAMember(teamId, userId);
        }

        public bool DelFriendFromTeam(string teamId, string userId)
        {
            return TeamDB.DeleteAMember(teamId, userId);
        }

        public bool SetIpPort(string userId, HustQQModel.IpPort ipPort)
        {
            //nononononononono
            throw new NotImplementedException();
        }

        public HustQQModel.IpPort GetIpPort(string userId)
        {
            HustQQModel.User u = UserDB.GetUserInfo(userId, true);
            if (u == null)
                return null;
            return new HustQQModel.IpPort(u.ip, u.port);
            
        }



        #region IDataInterface 成员


        //public string NewTeamToUser(string myId, string teamName)
        //{
        //    throw new NotImplementedException();
        //}

        #endregion
    }
}
